package org.theSeed.fileConfig.utils;

import cn.hutool.extra.spring.SpringUtil;
import org.theSeed.fileConfig.config.SeedFileHolder;
import org.theSeed.fileConfig.pojo.prop.SeedFileUploadProp;
import org.theSeed.fileContract.pojo.dto.*;
import org.theSeed.fileContract.pojo.vo.CancleChipFileProxyVo;
import org.theSeed.fileContract.pojo.vo.SeedCheckChipFileProxyVo;
import org.theSeed.fileContract.pojo.vo.SeedUploadChipFileInitProxyVo;
import org.theSeed.fileContract.pojo.vo.SeedUploadFileProxyVo;

import java.io.InputStream;
import java.util.Map;

/**
 * 文件上传工具
 */
public class SeedFileUtil {
    /**
     * 获取文件全局配置
     * @return
     */
    public static SeedFileUploadProp getSeedFileUploadProp(){
        return SpringUtil.getBean(SeedFileUploadProp.class);
    }

    /**
     * 获取文件上传持有者对象
     * @return
     */
    public static SeedFileHolder getSeedFileHolder(){
        return SpringUtil.getBean(SeedFileHolder.class);
    }

    /**
     * 获取文件上传持有者对象
     * @return
     */
    public static String getActiveInstance(){
        return getSeedFileUploadProp().getActiveInstanceName();
    }


    /**
     * 获取文件
     * @param seedGetFileProxyDto
     * @return
     */
    public static InputStream getFile(SeedGetFileProxyDto seedGetFileProxyDto){
        return getSeedFileHolder().getFile(seedGetFileProxyDto);
    }


    /**
     * 文件上传
     * @param seedUploadFileDto
     * @return
     */
    public static SeedUploadFileProxyVo uploadFile(SeedUploadFileDto seedUploadFileDto){
        return getSeedFileHolder().uploadFile(seedUploadFileDto);
    }

    /**
     * 文件上传更新
     * @param seedUpdateFileProxyDto
     * @return
     */
    public static SeedUploadFileProxyVo updateFile(SeedUpdateFileProxyDto seedUpdateFileProxyDto){
        return getSeedFileHolder().updateFile(seedUpdateFileProxyDto);
    }

    /**
     * 文件删除
     * @param seedDeleteFileProxyDto
     * @return
     */
    public static SeedUploadFileProxyVo deleteFile(SeedDeleteFileProxyDto seedDeleteFileProxyDto){
        return getSeedFileHolder().deleteFile(seedDeleteFileProxyDto);
    }

    /**
     * 分片上传 文件上传初始化
     * @param seedUploadChipFileInitDto
     * @return
     */
    public static SeedUploadChipFileInitProxyVo initUploadChipFile(SeedUploadChipFileInitDto seedUploadChipFileInitDto){
        return getSeedFileHolder().initUploadChipFile(seedUploadChipFileInitDto);
    }

    /**
     * 分片上传
     * @param seedUploadChipFileProxyDto
     * @return
     */
    public static SeedUploadFileProxyVo uploadChipFile(SeedUploadChipFileProxyDto seedUploadChipFileProxyDto){
        return getSeedFileHolder().uploadChipFile(seedUploadChipFileProxyDto);
    }

    /**
     * 上传文件合并
     * @param mergeChipFileProxyDto
     * @return
     */
    public static SeedUploadFileProxyVo mergeChipFile(MergeChipFileProxyDto mergeChipFileProxyDto){
        return getSeedFileHolder().mergeChipFile(mergeChipFileProxyDto);
    }

    /**
     * 文件上传检查
     * @param checkChipFileProxyDto
     * @return
     */
    public static SeedCheckChipFileProxyVo checkChipFile(CheckChipFileProxyDto checkChipFileProxyDto){
        return getSeedFileHolder().checkChipFile(checkChipFileProxyDto);
    }

    /**
     * 文件分片上传取消
     * @param cancleChipFileProxyDto
     * @return
     */
    public static CancleChipFileProxyVo cancleChipFile(CancleChipFileProxyDto cancleChipFileProxyDto){
        return getSeedFileHolder().cancleChipFile(cancleChipFileProxyDto);
    }

    /**
     * 解密信息
     * @param enCodeDataStr
     * @return
     */
    public static Map<String, Object> deCodeData(String enCodeDataStr) {
        return getSeedFileHolder().deCodeData(enCodeDataStr);
    }
}
